<template>
  <div class="contenter">
    <el-row>
      <el-col :span="12" :xs="0"></el-col>
      <el-col :span="12" :xs="24">
        <div class="right">
          <div class="top">
            <svg-icon name="tu" width="110px" height="110px"></svg-icon>
          </div>
          <div class="title">
            <svg-icon name="Slice" width="621px" height="108px"></svg-icon>
          </div>
          <div class="middle">
            <div class="account_box">
              <div class="tip">输入账户名</div>
              <div class="user">
                <svg-icon name="account" width="32px" height="32px"></svg-icon>
                <el-input
                  class="input"
                  v-model="loginForm.username"
                  placeholder="输入账户名"
                ></el-input>
              </div>
              <span></span>
            </div>
            <div class="password_box">
              <div class="tip">设置新密码</div>
              <div class="user">
                <svg-icon name="password" width="32px" height="32px"></svg-icon>
                <el-input
                  class="input"
                  v-model="loginForm.password"
                  show-password
                  placeholder="含大写字母、数字的6-12个字符密码"
                ></el-input>
              </div>
              <span></span>
            </div>
            <div class="password_box_plus">
              <div class="tip">确认新密码</div>
              <div class="user">
                <svg-icon name="password" width="32px" height="32px"></svg-icon>
                <el-input
                  class="input"
                  v-model="loginForm.confimPassword"
                  show-password
                  placeholder="含大写字母、数字的6-12个字符密码"
                ></el-input>
              </div>
              <span></span>
            </div>
            <!-- <el-input :prefix-icon="User"></el-input>
           <el-input :prefix-icon="Lock" show-password></el-input> -->
          </div>
          <div class="botton" @click="register">注册</div>
          <div class="return_login">
            <svg-icon name="back"></svg-icon>
            <div class="return_box" style="margin: 0 2px" @click="toLogin">
              返回登录
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
// import { User, Lock } from '@element-plus/icons-vue'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
//引入用户相关仓库
import useUserStore from '@/store/modules/user'
import { ElMessage } from 'element-plus'
//获取路由器对象
const $router = useRouter()
//定义注册表单收集数据
const loginForm = ref({ username: '', password: '', confimPassword: '' })
const userStore = useUserStore()
const toLogin = () => {
  $router.push('/login')
}
//判断字符串是否含有大写字符
//点击注册触发的按钮
const register = async () => {
  if (loginForm.value.password === loginForm.value.confimPassword) {
    try {
      await userStore.userRegister(loginForm.value)
      ElMessage({
        type: 'success',
        message: '注册成功',
      })
      $router.push('/login')
    } catch (error) {
      ElMessage({
        type: 'error',
        message: '注册失败',
      })
    }
  } else {
    ElMessage({
      type: 'error',
      message: '密码强度不够',
    })

    Object.assign(loginForm.value, {
      username: '',
      password: '',
      confimPassword: '',
    })
  }
}
</script>

<style scoped lang="scss">
.contenter {
  width: 100vw;
  height: 100vh;
  background: url('../../../src/assets/images/background.png') no-repeat;
  background-size: cover;
  .right {
    margin-top: 110px;
    margin-left: 74px;
    // margin-bottom: 206px;
    margin-right: 259px;
    height: 683px;
    width: 621px;
    // background: pink;
    :deep(.el-input__wrapper) {
      background-color: transparent;
      box-shadow: none;
    }
    :deep(.el-input__inner) {
      color: #fff;
    }
    .top {
      margin-left: 261px;
      width: 110px;
      height: 110px;
      // background: red;
    }
    .title {
      margin-top: 22px;
      width: 621px;
      height: 108px;
      // background: skyblue;
    }
    .middle {
      margin-top: 63px;
      .account_box {
        .tip {
          width: 120px;
          height: 28px;
          font-weight: normal;
          font-size: 20px;
          color: #ffffff;
          line-height: 23px;
          text-align: left;
        }
        .user {
          display: flex;
          .input {
            margin-left: 44px;
          }
          .input {
            margin-left: 44px;
            border-radius: 0px 0px 0px 0px;
            opacity: 0.8;
          }
        }
        span {
          display: block;
          margin-top: 10px;
          width: 621px;
          height: 1px;
          border: 1px solid #c2c9cf;
          opacity: 0.7;
        }
      }
      .password_box {
        margin-top: 52px;
        .user {
          display: flex;
          .input {
            margin-left: 44px;
          }
        }
        .tip {
          width: 120px;
          height: 28px;
          font-size: 20px;
          color: #ffffff;
          line-height: 23px;
        }
        span {
          display: block;
          margin-top: 10px;
          width: 621px;
          height: 1px;
          border: 1px solid #c2c9cf;
          opacity: 0.7;
        }
      }
      .password_box_plus {
        margin-top: 52px;
        .user {
          display: flex;
          .input {
            margin-left: 44px;
          }
        }
        .tip {
          width: 120px;
          height: 28px;
          font-size: 20px;
          color: #ffffff;
          line-height: 23px;
        }
        span {
          display: block;
          margin-top: 10px;
          width: 621px;
          height: 1px;
          border: 1px solid #c2c9cf;
          opacity: 0.7;
        }
      }
    }
    .botton {
      margin-left: 101px;
      margin-top: 50px;
      margin-right: 90px;
      width: 430px;
      height: 55px;
      background: rgba(85, 137, 191, 0.2);
      border-radius: 4px 4px 4px 4px;
      border: 2px solid #5982f0;
      color: #e9f1fa;
      font-size: 22px;
      text-align: center;
      line-height: 50px;
      // background: pink;
    }
    .return_login {
      display: flex;
      align-items: center;
      margin-top: 27px;
      margin-left: 281px;
    }
  }
}
</style>
